package leetcode21_30;

import org.junit.Test;

/**
 * @author shhjiang_001
 * @create 2020-06-15 11:56
 */




public class Solution28 {
    public int strStr(String haystack, String needle) {
        if (needle.length() > haystack.length()) return -1;
        int le = 0;
        int ri = le+needle.length();
        while (ri <= haystack.length()){
            if (haystack.indexOf(le) == needle.indexOf(0)){
                String s = haystack.substring(le, ri);
                if (s.equals(needle)) return le;
            }
            le++;
            ri = le+needle.length();
        }
        return -1;
    }
    @Test
    public void test(){
        Solution28 solution28 = new Solution28();
        int i = solution28.strStr("hello", "ll");
        System.out.println(i);
    }
}
